package org.nch.videoLauncher.task;

import org.nch.videoLauncher.domain.Profile;
import org.nch.videoLauncher.repository.ProfileRepository;

import java.util.prefs.Preferences;

/**
 * Created by IntelliJ IDEA.
 * User: bill
 * Date: Dec 13, 2008
 * Time: 8:32:35 PM
 * To change this template use File | Settings | File Templates.
 */
public class ProfileUtil {

    private static Profile activeProfile;
    private static Preferences appPrefs;

    static {
        // load selected profile ID from preferences.

        appPrefs = Preferences.userNodeForPackage(ProfileUtil.class);
        Integer activeProfileId = appPrefs.getInt("VideoBrain Active Profile", 1);
        ProfileRepository pfr = new ProfileRepository();
        activeProfile = pfr.getById(activeProfileId);
        if (activeProfile == null)
        {
            activeProfile = new Profile("Default", "/video");
            activeProfile = pfr.persist(activeProfile);
        }
    }

    public static Profile getProfile() {
        return activeProfile;
    }

    public static void setActiveProfileId(Integer activeProfileId){
        ProfileRepository pfr = new ProfileRepository();
        activeProfile = pfr.getById(activeProfileId);
    }

    public static void saveActiveProfileId(){
        appPrefs.putInt("VideoBrain Active Profile", activeProfile.getId());        
    }

}
